package com.wuchao.spring.fanse;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Author wuchao66
 * @Date 2022/7/1 11:03
 * @Version 1.0
 */
public class TFS {
    public static void main(String[] args) {
       /* Fanse fanse = new Fanse();
        fanse.show("xx");*/
        //Class<?> aClass = Class.forName("com.wuchao.spring.fanse.Fanse");
        //反射得到他的影子
        Class<Fanse> fanseClass = Fanse.class;
        Method[] declaredMethods = fanseClass.getDeclaredMethods();
        for(Method method : declaredMethods){
            System.out.println(method.getName());
        }
        //上面知道已经有一个show 我要拿下来
        try {
            Method show = fanseClass.getMethod("show", String.class);
            //回调运行
            show.invoke(fanseClass.newInstance(),"这就是反射，你爱了吗");
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
       /* try {
            Fanse fanse = fanseClass.newInstance();//真正的实现类
            fanse.show("xx");
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }*/


    }

}
